<?php	
  	/*\
  	 *	String - oh.framework
  	 *	---------------------
  	 *	name: string
  	 *  sign: 
  	 *	description: usefull string functions
  	\*/
	
	// Interface function	
	function oh_module_string($tokens) {
		global $oh_object_string;
		return $oh_object_string;	
	} 

	// Option file required
	//require_once($oh['path']."...");
	//require_once($oh['path']."...");
	
	// Main class of module
	class oh_class_string {		
		function oh_class_string() {
		}
		function substr($string,$from,$to) {
			$p0 = strpos($string,$from);
			if ($p0 !== false) {
				$p1 = strpos($string,$to,$p0);
				if ($p1 !== false) {
					return trim(substr($string,$p0+strlen($from),$p1-$p0-strlen($from)));
				} else {
					return trim(substr($string,$p0));	
				}
			}
			return "";
		}		
      	function endswith($FullStr, $EndStr) {
          	$StrLen = strlen($EndStr);
          	$FullStrEnd = substr($FullStr, strlen($FullStr) - $StrLen);
          	return $FullStrEnd == $EndStr;
      	}
      	function charquot($a,$b,$offset_a=0,$offset_b=0) {
			$o = 0;
			$max = strlen($this->max($a,$b));
      		for($i=0;$i<$max;$i++) {
				$c_a = $a{$i+$offset_a};
				$c_b = $b{$i+$offset_b};
	  			if (($c_a != '')&&($c_b != '')&&($c_a == $c_b)) {
	  				$o++;
	  			}      			
      		}
      		return $o;
      	}
      	function max($a,$b) {
			if (strlen($a)>=strlen($b)) return $a; else return $b;
      	}
      	function charmaxquot($a,$b) {
			$oa = 0;
			$ob = 0;
			$max = 0;			
      		for($i=0;$i<strlen($a);$i++) {
	      		for($j=0;$j<strlen($b);$j++) {
		  			$tmp = $this->charquot($a,$b,$i,$j);
					if ($tmp >= $max) {
						$max = $tmp;
						$oa = $i;
						$ob = $j;
					}					
				}
      		}
      		return array($oa,$ob);
      	}
      	function br2nl($text) {
      		$temp = $text;
      		$temp = str_replace("<br>","\n",$temp);	
      		$temp = str_replace("<br/>","\n",$temp);	
      		$temp = str_replace("<br />","\n",$temp);	
      		$temp = str_replace("<BR>","\n",$temp);	
      		$temp = str_replace("<BR/>","\n",$temp);	
      		$temp = str_replace("<BR />","\n",$temp);	
      		$temp = strip_tags($temp);	
			return $temp;
      	}
      	function flat_ascii($text) {
      		$o = "";
      		for($i=0;$i<strlen($text);$i++) {
      			$c = $text{$i};      		
      			$a = ord($c);
      			if (($a>=32)&&($a<127)) {
      				$o = $o+$c;
      			}
      		}
      		return $o;
      	}
      	function formatting($text) {
      		$o = $text;
      		$o = trim($o);
      		$o = nl2br($o);
      		$o = str_replace("\t","&nbsp;&nbsp;&nbsp;&nbsp;",$o);
      		return $o;
      	}
	}
	
	// Main object of module
	global $oh_object_string;
	$oh_object_string = new oh_class_string();
?>
